from app.models.property import Property
from app.extensions import db

#根据用户名查找对应的房源
def get_property_byUsername(username):
    return Property.query.filter_by(username=username).all()

#新增用户房源
def add_property_byUsername(property,username):
    property.username = username
    db.session.add(property)
    db.session.commit()

#删除用户房源信息
# 根据房源 ID 删除房源信息
def delete_property(property_id):
    property = Property.query.get(property_id)
    if property:
        db.session.delete(property)
        db.session.commit()
    return property

#编辑用户房源
def update_property(property):
    target_property = Property.query.get(property.id)
    target_property.username = property.username
    target_property.address = property.address
    target_property.hoseType = property.hoseType
    target_property.area = property.area
    target_property.sumCost = property.sumCost
    target_property.deposit = property.deposit
    target_property.Decoration = property.Decoration
    db.session.commit()

